package com.ruoyi.store.controller;

import java.util.List;

import com.ruoyi.store.service.IPayslipRateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.store.domain.PayslipRate;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工资提成Controller
 * 
 * @author ml
 * @date 2023-05-02
 */
@Controller
@RequestMapping("/store/rate")
public class PayslipRateController extends BaseController
{
    private String prefix = "store/rate";

    @Autowired
    private IPayslipRateService payslipRateService;

    @RequiresPermissions("store:rate:view")
    @GetMapping()
    public String rate()
    {
        return prefix + "/rate";
    }

    /**
     * 查询工资提成列表
     */
    @RequiresPermissions("store:rate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayslipRate payslipRate)
    {
        startPage();
        List<PayslipRate> list = payslipRateService.selectPayslipRateList(payslipRate);
        return getDataTable(list);
    }

    /**
     * 导出工资提成列表
     */
    @RequiresPermissions("store:rate:export")
    @Log(title = "工资提成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayslipRate payslipRate)
    {
        List<PayslipRate> list = payslipRateService.selectPayslipRateList(payslipRate);
        ExcelUtil<PayslipRate> util = new ExcelUtil<PayslipRate>(PayslipRate.class);
        return util.exportExcel(list, "工资提成数据");
    }

    /**
     * 新增工资提成
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工资提成
     */
    @RequiresPermissions("store:rate:add")
    @Log(title = "工资提成", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayslipRate payslipRate)
    {
        return toAjax(payslipRateService.insertPayslipRate(payslipRate));
    }

    /**
     * 修改工资提成
     */
    @RequiresPermissions("store:rate:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PayslipRate payslipRate = payslipRateService.selectPayslipRateById(id);
        mmap.put("payslipRate", payslipRate);
        return prefix + "/edit";
    }

    /**
     * 修改保存工资提成
     */
    @RequiresPermissions("store:rate:edit")
    @Log(title = "工资提成", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayslipRate payslipRate)
    {
        return toAjax(payslipRateService.updatePayslipRate(payslipRate));
    }

    /**
     * 删除工资提成
     */
    @RequiresPermissions("store:rate:remove")
    @Log(title = "工资提成", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(payslipRateService.deletePayslipRateByIds(ids));
    }
}
